﻿Chenxin.UI.PgServiceCharge = Chenxin.extend(Chenxin.UI.PageCommon, {
    actionUrl: "/service/logic/ShowListServiceCharge.ashx",
    createGrid: function() {
        return new Chenxin.UI.JsonGrid({
            actionUrl: this.actionUrl + '?op=getlist',
            pageSize: 10,
            renderTo: 'divShowLsSvrCharge',
            hasCheckBox: false,
            //autoOddCls: false,
            scope: this,
            modelId: 'ReceiptId',
            id: 'ChargeList',
            title: '服务费收据',
            scope: this,
            columns: {
                Status: {
                    width: 50,
                    head: "状态",
                    sortable: true
                },
                ReceiptCode: {
                    width: 150,
                    head: "服务费收据编号",
                    sortable: true
                },
                ReceiptDepart: {
                    width: 180,
                    head: "收款门店",
                    sortable: true
                },
                ReceiptEmployee: {
                    width: 70,
                    head: "收款业务员",
                    sortable: true
                },
                GetedTime: {
                    width: 100,
                    head: "领取时间",
                    sortable: true
                },
                ContractCode: {
                    width: 130,
                    head: "成交编号",
                    sortable: true
                },
                BusinessType: {
                    width: 60,
                    head: "成交类型",
                    sortable: true
                },
                HouseAddress: {
                    width: 300,
                    head: "物业地址",
                    sortable: true
                },
                CustomerName: {
                    width: 140,
                    head: "客户姓名",
                    sortable: true
                },
                Mobile: {
                    width: 140,
                    head: "客户手机"
                },
                Phone: {
                    width: 100,
                    head: "客户电话"
                },
                CustomerAddress: {
                    width: 300,
                    head: "发票邮寄地址"
                },
                ZipCode: {
                    width: 70,
                    head: "邮编",
                    sortable: true
                },
                ReceiptMoneyName: {
                    width: 80,
                    head: "款项性质",
                    sortable: true
                },
                GetedMoney: {
                    width: 80,
                    head: "金额",
                    sortable: true
                },
                AddTime: {
                    width: 100,
                    head: "建档时间",
                    sortable: true
                },
                AddEmployee: {
                    width: 70,
                    head: "建档人",
                    sortable: true
                }
            },
            rowRenderer: function(row, index, dl) {
                if (row.Status == "作废") {
                    dl.css("background-color", "gray");
                } else {
                    //dl.css("background-color", "#80FF80");
                }
            }
        });
    },
    createSearch: function() {
        return new Chenxin.UI.SrhServiceCharge({
            scope: this
        });
    },
    initEvent: function() {
        var objPg = this;
        /***************事件：底部按钮点击事件**********/
        $('.LeftFooter a').click(function() {
            objPg.bindBottomBar(this);
        });
    },
    bindBottomBar: function(obj) {
        switch (obj.name) {
            //服务费收据登记                                              
            case "RegServiceCharge":
                this.RegServiceCharge();
                break;
            //查看服务费收据                          
            case "ViewServiceCharge":
                this.ViewServiceCharge();
                break;
            //服务费收据作废                                               
            case "CancelServiceCharge":
                this.CancelServiceCharge();
                break;
            //登记合同编号                        
            case "RegContractCode":
                this.RegContractCode();
                break;
            case "PrintService":
                this.Print();
                break;
            default:
                alert("此功能未开通");
                break;
        }
    },
    Print: function() {
        var objFrm = this;
        if (!objFrm.currentId) {
            alert("请选择一条收据进行操作！");
            return false;
        }
        if (objFrm.printInForm == undefined) {
            objFrm.printInForm = new Chenxin.UI.PrintInServiceForm({
                scope: objFrm,
                op: 'reprintview'
            });
        };
        objFrm.printInForm.reset();
        if (objFrm.printInForm.show('reprintview') == false) return;

        Chenxin.ajax({
            type: "get",
            dataType: "json",
            url: objFrm.printInForm.actionUrl,
            data: { op: 'getprintmodel', billId: this.grid.getCurrentRecord().ReceiptId },
            onSuccess: function(data) {
                objFrm.printInForm.fitData(data.model);
            }
        });
    },
    RegServiceCharge: function() {

        if (this.RegFrm == undefined) {
            this.CreateRegServiceChargeFrm();
        }
        var initVal = eval("(" + $("#ctl00_main_hidUserInfo").val() + ")");
        this.RegFrm.reset();
        if (this.RegFrm.show()) {
            this.RegFrm.fitData(initVal);
        }
    },
    ViewServiceCharge: function() {
        if (!this.currentId) {
            alert("请选择一条收据进行操作！");
            return false;
        }

        if (this.ViewFrm == undefined) {
            this.ViewFrm = new Chenxin.UI.ViewServiceChargeFrm({
                scope: this
            });
        }
        this.ViewFrm.fitData(this.grid.getCurrentRecord());
        this.ViewFrm.grid.reload({ ReceiptId: this.currentId });
        this.ViewFrm.show();
    },
    CreateRegServiceChargeFrm: function() {
        var objPg = this;
        this.RegFrm = new Chenxin.UI.RegServiceChargeFrm({
            scope: this,
            beforeFitData: function(data) {
                if (data != "{}") {
                    this.RegFrm.comboList[1].param.fatherid = data.ReceiptCityId;
                    this.RegFrm.comboList[1].reload(data.ReceiptCompanyId);
                    this.RegFrm.comboList[2].param.fatherid = data.ReceiptCompanyId;
                    this.RegFrm.comboList[2].reload(data.ReceiptDepartId);
                    this.RegFrm.comboList[3].loadUser(data.ReceiptDepartId);
                }
            },
            afterGetFormJson: function(json) {

                delete json.ItemPayMoney;
                delete json.ItemMemo;
                delete json.ItemCode;

                var lsPayItem = [];
                var idxCnt = 0;
                var objPg = this;
                var payItem = {};
                $("#tbPayItems tbody tr").each(function() {
                    payItem = {};
                    if ($(this).find("input[name='ItemPayMoney']").length > 0) {
                        if (objPg.RegFrm.lsPayMode[idxCnt].getValue() == objPg.RegFrm.lsPayMode[idxCnt].defVal) {
                            idxCnt = idxCnt + 1;
                            return true;
                        } else {
                            payItem.PayMode = objPg.RegFrm.lsPayMode[idxCnt].getValue();
                            payItem.PayMoney = $(this).find("input[name='ItemPayMoney']:eq(0)").val();
                            payItem.PayCode = $(this).find("input[name='ItemCode']:eq(0)").val();
                            payItem.Memo = $(this).find("input[name='ItemMemo']:eq(0)").val();
                        }
                        lsPayItem.push(payItem);
                    }
                    idxCnt = idxCnt + 1;
                });
                objPg.RegFrm.additionalParam.PayItems = "[" + lsPayItem.toString() + "]";
            },
            saveSucc: function(data) {
                var _this = this;
                _this.CurModel = data.model;
                if (_this.printInForm == undefined) {
                    _this.printInForm = new Chenxin.UI.PrintInServiceForm({
                        scope: _this,
                        op: 'printview'
                    });
                }

                if (_this.printInForm.show('reprintview') == false) return;
                _this.printInForm.reset();
                _this.printInForm.fitData(_this.CurModel);
                _this.grid.reload();
            }
        })
    },
    CancelServiceCharge: function() {
        if (!this.currentId) {
            alert("请选择一条收据进行操作！");
            return false;
        }

        if (this.grid.getCurrentRecord().Status == "作废") {
            alert("此收据已作废！");
            return false;
        }

        if (!confirm("确定要作废此收据吗？")) {
            return false;
        }

        if (this.CancelFrm == undefined) {
            this.CancelFrm = new Chenxin.UI.CancelChargeForm({
                scope: this,
                afterGetFormJson: function(json) {
                    json.ReceiptId = this.currentId;
                },
                saveSucc: function() {
                    this.reloadGrid();
                }
            });
        }
        this.CancelFrm.reset();
        this.CancelFrm.show();
    },
    RegContractCode: function() {
        if (!this.currentId) {
            alert("请选择一条收据进行操作！");
            return false;
        }

        if (this.grid.getCurrentRecord().Status == "作废") {
            alert("此收据已作废！");
            return false;
        }

        if (this.RegContractFrm == undefined) {
            this.RegContractFrm = new Chenxin.UI.RegContractForm({
                scope: this,
                afterGetFormJson: function(json) {
                    json.ReceiptId = this.currentId;

                    delete json.ReceiptCode;
                    delete json.ReceiptMoneyName;
                    delete json.BusinessType;
                    delete json.CustomerName;
                    delete json.GetedMoney;
                    delete json.GetedTime;
                    delete json.ReceiptDepart;
                    delete json.ReceiptEmployee;
                    delete json.CHouseAddress;
                    delete json.VenderName;
                    delete json.BuyerName;
                    delete json.VRealCommision;
                    delete json.BRealCommision;
                    delete json.VConsulting;
                    delete json.BConsulting;
                    delete json.VenderDepartName;
                    delete json.BuyerDepartName;
                    delete json.VenderUserName;
                    delete json.BuyerUserName;
                },
                saveSucc: function() {
                    this.reloadGrid();
                }
            });
        }
        this.RegContractFrm.reset();
        if (this.RegContractFrm.show()) {
            this.RegContractFrm.fitData(this.grid.getCurrentRecord());
        }
    }
});

Chenxin.UI.SrhServiceCharge = Chenxin.extend(Chenxin.UI.SearchCommon, {
    actionUrl: "/service/logic/ShowListServiceCharge.ashx",
    id: 'divCondition',
    createComboList: function() {
        //状态
        var cmbStatus = new Chenxin.UI.Combo({
            containerId: '#Status',
            tbxWidth: 45,
            items: comboCommon.ChargeStatus
        });

        //城市，公司，商圈，部门，人员
        var combl = new Chenxin.UI.StructComboList();
        var structs = combl.comboList;
        structs.push(cmbStatus);

        return structs;
    },
    initEvent: function() {
        var ojbSrh = this;
        $("#btnSearch").click(function() {
        var data = ojbSrh.scope.search.getParamJson();
            ojbSrh.scope.reloadGrid(data);
        });

        $('#txtKeyword').defText({
            deftxt: '输入收据编号/成交编号/物业地址'
        }) 
    }
});

/*
**服务费收据登记
*/
Chenxin.UI.RegServiceChargeFrm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: "/service/logic/ShowListServiceCharge.ashx",
    id: "jqmRegFrm",
    renderTo: "jqmRegFrm",
    title: "服务费收据登记",
    op: "regcharge",
    defBBtn: false,
    maxItemCnt: 0,
    lsPayMode: [],
    jqmWidth: 615,
    createBBtn: function() {
        return [{ text: '确定', handler: this.frmSubmit, scope: this },
                { text: '取消', handler: this.hide, scope: this}];
    },
    clientChk: function() {
        var objFrm = this;
        //收款部门
        if (this.comboList[2].getValue() == this.comboList[2].defVal) {
            alert("请选择收款部门！");
            return false;
        }
        //收款人员
        if (this.comboList[3].getValue() == "") {
            alert("请选择收款人员！");
            return false;
        }
        //款项性质
        if (this.comboList[4].getValue() == this.comboList[4].defVal) {
            alert("请选择款项性质！");
            return false;
        }
        //物业地址
        if ($("#RegHouseAddress").val() == "") {
            alert("请输入物业地址！");
            $("#RegHouseAddress").focus();
            return false;
        }
        //成交类型
        if (this.comboList[5].getValue() == this.comboList[5].defVal) {
            alert("请选择成交类型！");
            return false;
        }
        //客户姓名
        if ($("#RegCustomerName").val() == "") {
            alert("请输入客户姓名！");
            $("#RegCustomerName").focus();
            return false;
        }

        var Mobile = $("#RegMobile").val();
        var Phone = $("#RegPhone").val();

        if (Mobile == "" && Phone == "") {
            alert("手机和电话至少输入一项！");
            $("#RegMobile").focus();
            return false;
        } else if (Mobile != "") {
            if (!Mobile.isMobile()) {
                alert("输入的手机号码格式不正确！");
                $("#RegMobile").focus();
                return false;
            }
        }

        //收取时间
        if ($("#RegGetedTime").val() == "") {
            alert("请输入收取时间！");
            $("#RegGetedTime").focus();
            return false;
        }
        //收据金额
        var RegGetedMoney = $("#RegGetedMoney").val();
        if (RegGetedMoney == "") {
            alert("请输入收据金额！");
            $("#RegGetedMoney").focus();
            return false;
        } else if (!RegGetedMoney.isNum()) {
            alert("收据金额为非金额格式！");
            $("#RegGetedMoney").focus();
            return false;
        }

        var idxCnt = 0;
        var valItemMoney;
        var valType;
        var TotalMoney = 0;
        var bNeedChkTotal = true;
        $("#tbPayItems tbody tr").each(function() {
            valItemMoney = $(this).find("input[name='ItemPayMoney']:eq(0)").val();
            if (valItemMoney == undefined) {
                return true;
            }
            valMode = objFrm.lsPayMode[idxCnt].getValue();
            if (valItemMoney == "" && valMode == "请选择") {
                return true;
            }
            if (valItemMoney != "" && valMode == "请选择") {
                alert("请选择收取方式！");
                bNeedChkTotal = false;
                return false;
            } else if (valItemMoney == "" && valMode != "请选择") {
                alert("请输入收取金额！");
                bNeedChkTotal = false;
                return false;
            } else if (!valItemMoney.isNum()) {
                alert("输入的收取金额为非金额格式！");
                bNeedChkTotal = false;
                return false;
            } else {
                TotalMoney = TotalMoney + parseFloat(valItemMoney);
            }
            idxCnt = idxCnt + 1;
        });
        if (bNeedChkTotal) {
            if (RegGetedMoney != TotalMoney) {
                alert("款项相加总金额需等于收据金额！");
                return false;
            }
        } else {
            return false;
        }
        return true;
    },
    frmSubmit: function() {
        if (this.clientChk()) {
            this.save();
        }
    },
    createForm: function() {
        var strRet = "";
        strRet = strRet + '<table class="tbl_f">';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th style="width:100px">收款城市：</th>';
        strRet = strRet + '<td style="width: 214px;"><div id="RegCity"  style="z-index:105" ></div></td>';
        strRet = strRet + '<th style="width:100px">收款公司：</th>';
        strRet = strRet + '<td><div id="RegCompany"  style="z-index:104" ></div></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>收款部门：</th>';
        strRet = strRet + '<td><div id="RegDepart"  style="z-index:103" ></div></td>';
        strRet = strRet + '<th>收款人员：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" readonly id="txtRegEmp" style="width: 127px;" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>成交编号：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "ContractCode" id="RegContractCode"  style="width: 127px;"/><div class="btn btn2"><a title="获取信息" href="javascript:void(0)" id="aGetInfo"><span>获取信息</span></div></td>';
        strRet = strRet + '<th>款项性质：</th>';
        strRet = strRet + '<td><div id="RegMoneyType" style="z-index:102"></div></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>物业地址：</th>';
        strRet = strRet + '<td colspan="3"><input type="text" class="inputbox_n fl" style="width:444px" name = "HouseAddress" id="RegHouseAddress" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>成交类型：</th>';
        strRet = strRet + '<td><div id="RegBusinessType" style="z-index:101"></div></td>';
        strRet = strRet + '<th>客户姓名：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "CustomerName" id="RegCustomerName"  style="width: 127px;"/></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>手机号码：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "Mobile" id="RegMobile" style="width: 127px;"/></td>';
        strRet = strRet + '<th>电话号码：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "Phone" id="RegPhone" style="width: 127px;"/></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>收取时间：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "GetedTime" readonly id="RegGetedTime" style="width: 127px;" /></td>';
        strRet = strRet + '<th>收据金额：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "GetedMoney" id="RegGetedMoney"  style="width: 127px;" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<td colspan="4">';
        strRet = strRet + '<div style="overflow:scoll;height:142px;overflow:auto;width:568px">';
        strRet = strRet + '<table class="tabsorternew" id="tbPayItems" style="width:515px;margin-left:35px">';
        strRet = strRet + '<thead>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th style="text-align:center">收取方式</th>';
        strRet = strRet + '<th style="text-align:center">金额</th>';
        strRet = strRet + '<th style="text-align:center">交款编号</th>';
        strRet = strRet + '<th style="text-align:center">备注</th>';
        strRet = strRet + '<th style="text-align:center">操作</th>';
        strRet = strRet + '</tr>';
        strRet = strRet + '</thead>';
        strRet = strRet + '<tbody>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<td colspan="5"><div class="btn btn5 fr"><a title="添加收取明细" href="javascript:void(0)" id="aAddPayItem"><span>添加收取明细</span></div></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '</tbody>';
        strRet = strRet + '</table>';
        strRet = strRet + '</div>';
        strRet = strRet + "</td>"
        strRet = strRet + '</tr>'
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>发票邮寄地址：</th>';
        strRet = strRet + '<td colspan="3"><input type="text" class="inputbox_n fl" name = "CustomerAddress" style="width:444px" /></td>';
        strRet = strRet + '</tr>'
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>邮编：</th>';
        strRet = strRet + '<td colspan="3"><input type="text" class="inputbox_n fl" name = "ZipCode"  style="width: 127px;" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>备注：</th>';
        strRet = strRet + '<td colspan=3><textarea name="ReceiptMemo" cols="80" rows="5" style="width:447px" class="textarea_n" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '</table>';
        return strRet;
    },
    createComboList: function() {
        var initVal = eval("(" + $("#ctl00_main_hidUserInfo").val() + ")");
        //收据人员
        var RegEmp = new Chenxin.UI.RichModelTreeCombo({
            textBoxId: 'txtRegEmp',
            containerId: '#txtRegEmp',
            inModelType: 'all',
            txtModelName: 'ReceiptEmployee',
            name: 'ReceiptEmployeeId',
            required: false,
            singleSelect: true
        });
        //收据部门
        var RegDepart = new Chenxin.UI.StructCombo({
            param: { op: 'getcompanydeparts' },
            containerId: '#RegDepart',
            name: 'ReceiptDepartId',
            inModelType: 'all',
            txtModelName: 'ReceiptDepart',
            colNum: 3,
            autoLoad: false,
            required: false,
            hasPage: true,
            hasSearch: true,
            pageSize: 60,
            tbxWidth: 96,
            colWidth: 80,
            onSelected: function() {
                if (this.getValue() != this.defVal) {

                    RegEmp.loadUser(this.getValue());
                }
            }
        });
        //收据公司
        var RegCompany = new Chenxin.UI.StructCombo({
            param: { op: 'getcompany' },
            containerId: '#RegCompany',
            name: 'ReceiptCompanyId',
            inModelType: 'all',
            txtModelName: 'ReceiptCompany',
            required: false,
            autoLoad: false,
            tbxWidth: 96,
            colWidth: 80,
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    RegDepart.clearItems();
                } else {
                    RegDepart.param.fatherid = this.getValue();
                    RegDepart.reload();
                }
            }
        });
        //收据城市
        var RegCity = new Chenxin.UI.StructCombo({
            param: { op: 'getcity' },
            containerId: '#RegCity',
            name: 'ReceiptCityId',
            inModelType: 'all',
            txtModelName: 'ReceiptCity',
            required: false,
            tbxWidth: 96,
            colWidth: 80,
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    RegCompany.clearItems();
                } else {
                    RegCompany.param.fatherid = this.getValue();
                    RegCompany.reload();
                }
                RegDepart.clearItems();
            }
        });
        //款项性质
        var RegMoneyType = new Chenxin.UI.Combo({
            containerId: "#RegMoneyType",
            name: 'ReceiptMoneyName',
            tbxWidth: 96,
            items: comboCommon.ServiceChargeType
        });
        //成交类型
        var BusinessType = new Chenxin.UI.Combo({
            containerId: "#RegBusinessType",
            name: 'BusinessType',
            tbxWidth: 96,
            items: comboCommon.BusinessType
        });
        return [RegCity, RegCompany, RegDepart, RegEmp, RegMoneyType, BusinessType]
    },
    addPayItem: function(RowCnt) {
        var strRet = "";
        var objAddBefore = $("#tbPayItems").children("tbody").children("tr:last");

        if (RowCnt == undefined) {
            RowCnt = 1;
        }
        for (var idxCnt = 0; idxCnt < RowCnt; idxCnt++) {
            strRet = "";
            strRet = strRet + '<tr>';
            strRet = strRet + '<td style="width:110px"><div id="PayMode' + this.maxItemCnt.toString().padLeft(2, "0") + '" class="SelectWrapSingle" style="z-index:' + (100 - this.maxItemCnt).toString() + '"  /></td>';
            strRet = strRet + '<td style="width:100px"><input type="text" class="inputbox_n fl" name = "ItemPayMoney" style="width:90px" /></td>';
            strRet = strRet + '<td style="width:110px"><input type="text" class="inputbox_n fl" name = "ItemCode" style="width:100px" /></td>';
            strRet = strRet + '<td style="width:150px"><input type="text" class="inputbox_n fl" name = "ItemMemo" style="width:140px" /></td>';
            strRet = strRet + '<td><a name="aDelPayItem" title="删除收取明细" href="javascript:void(0)" >删除</a></td>';
            strRet = strRet + '</tr>';

            objAddBefore.before(strRet);
            //支付方式
            var cmbFoundType = new Chenxin.UI.Combo({
                containerId: "#PayMode" + this.maxItemCnt.toString().padLeft(2, "0"),
                tbxWidth: 70,
                items: comboCommon.PayType
            });

            this.lsPayMode.push(cmbFoundType);
            this.maxItemCnt = this.maxItemCnt + 1;
        }
    },
    initEvent: function() {
        var objFrm = this;
        /***************事件：收取时间***************/
        $("#RegGetedTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
        /********事件：添加一条收取明细**********/
        $("#aAddPayItem").click(function() {
            objFrm.addPayItem(1);
        });
        /********事件：删除一条收取明细**********/
        $("A[name='aDelPayItem']").live("click", function() {
            var idxCurTr = $(this).parents("tbody:first").children("tr").index($(this).parents("tr:first"));
            $(this).parents("tr:first").remove();
            objFrm.lsPayMode.splice(idxCurTr, 1);
        });

        /********事件：获取信息事件**********/
        $("#aGetInfo").click(function() {

            if ($("#RegContractCode").val() == "") {
                return false;
            }
            Chenxin.ajax({
                type: "get",
                dataType: "text",
                paramType: 'json',
                async: false,
                url: objFrm.actionUrl,
                data: { op: 'getcontractinfo', ContractCode: $("#RegContractCode").val() },
                onSuccess: function(data, msg) {
                    $("#RegHouseAddress").val(data.HouseAddress);
                }
            });
        });
    },
    reset: function() {
        var objTrs = $("#tbPayItems").children("tbody").children("tr");
        this.fitData({});
        this.lsPayMode.length = 0;
        this.maxItemCnt = 0;
        objTrs.each(function() {
            if ($(this).find("input[name='ItemPayMoney']").length > 0) {
                $(this).remove();
            }
        });
        this.addPayItem(3);
    }
});

/*
* 查看服务费收据窗体
*/
Chenxin.UI.ViewServiceChargeFrm = Chenxin.extend(Chenxin.UI.FormCommon, {
    id: "jqmViewFrm",
    renderTo: "jqmViewFrm",
    actionUrl: "/service/logic/ShowListServiceCharge.ashx",
    op: "getpayitems",
    title:"查看服务费收据",
    hasfoot: false,
    createForm: function() {
        var strRet = "";
        strRet = strRet + '<table class="tbl_f">';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th style="width:100px">收款城市：</th>';
        strRet = strRet + '<td style="width:190px"><input type="text" name="ReceiptCity" readonly class="inputbox_n"></td>';
        strRet = strRet + '<th style="width:100px">收款公司：</th>';
        strRet = strRet + '<td><input type="text" name="ReceiptCompany" readonly class="inputbox_n"></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>收款部门：</th>';
        strRet = strRet + '<td><input type="text" name="ReceiptDepart" readonly class="inputbox_n"></td>';
        strRet = strRet + '<th>收款人员：</th>';
        strRet = strRet + '<td><input type="text" name="ReceiptEmployee" readonly class="inputbox_n"></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>成交编号：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "ContractCode" readonly /></td>';
        strRet = strRet + '<th>款项性质：</th>';
        strRet = strRet + '<td><input type="text" name="ReceiptMoneyName" readonly class="inputbox_n"></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>物业地址：</th>';
        strRet = strRet + '<td colspan="3"><input type="text" class="inputbox_n fl" style="width:422px" name = "HouseAddress" readonly /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>成交类型：</th>';
        strRet = strRet + '<td><input type="text" name="BusinessType" readonly class="inputbox_n"></td>';
        strRet = strRet + '<th>客户姓名：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "CustomerName" readonly /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>手机号码：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "Mobile" readonly /></td>';
        strRet = strRet + '<th>电话号码：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "Phone" readonly /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>收取时间：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "GetedTime" readonly /></td>';
        strRet = strRet + '<th>收据金额：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "GetedMoney" readonly /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>发票邮寄地址：</th>';
        strRet = strRet + '<td colspan="3"><input type="text" class="inputbox_n fl" name = "CustomerAddress" readonly style="width:422px" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>邮编：</th>';
        strRet = strRet + '<td colspan="3"><input type="text" class="inputbox_n fl" name = "ZipCode" readonly /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>备注：</th>';
        strRet = strRet + '<td colspan=3><textarea name="ReceiptMemo" cols="80" rows="5" readonly style="width:426px" class="textarea_n" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '</table>';
        strRet = strRet + '<div style="width:95%;margin-left:35px;margin-bottom:10px"><div id="divPayItems" ></div></div>';
        return strRet;
    },
    createGrid: function() {
        this.grid = new Chenxin.UI.JsonGrid({
            actionUrl: this.actionUrl + '?op=getpayitems',
            pageSize: 4,
            renderTo: 'divPayItems',
            hasCheckBox: false,
            autoLoad: false,
            scope: this,
            hasPage:false,
            height:115,
            width:500,
            id: 'PayItems',
            title: '收据明细',
            scope: this,
            columns: {
                PayMode: {
                    width: 120,
                    head: "收取方式",
                    sortable: true
                },
                PayMoney: {
                    width: 80,
                    head: "金额",
                    sortable: true
                },
                PayCode: {
                    width: 100,
                    head: "交款编号",
                    sortable: true
                },
                Memo: {
                    width: 350,
                    head: "备注" ,
                    style:"text-align:left"
                }
            }
        });
    },
    initComponent: function() {
        Chenxin.UI.ViewServiceChargeFrm.superclass.initComponent.call(this);
        this.createGrid();
    }
});

/*
* 作废服务费收据窗体
*/
Chenxin.UI.CancelChargeForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    id: "jqmCancelFrm",
    renderTo: "jqmCancelFrm",
    actionUrl: "/service/logic/ShowListServiceCharge.ashx",
    op: "cancel",
    defBBtn: true,
    title: "服务费收据作废",
    createForm: function() {
        var strRet = "";
        strRet = strRet + '<table class="tbl_f">';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th style="width:100px">作废理由：</th>';
        strRet = strRet + '<td><textarea name="UnusedReason" cols="80" rows="5" style="width:420px" class="textarea_n" id="txtaUnusedReason" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th></th>';
        strRet = strRet + '<td><div id="txtaUnusedReasonTip" style="float: left; margin-left: 5px; width: 180px; height: 26px; line-height: 26px; text-align: left;" ></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '</table>';
        return strRet;
    },
    initFormValidator: function() {
        //作废理由
        $("#txtaUnusedReason").formValidator({
            validatorgroup: this.id,
            onshow: "请输入作废理由！",
            onfocus: "作废理由为必输项目",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "作废理由不能为空！"
            },
            onerror: "作废理由不能为空！"
        });
    }
});

/*
* 成交编号登记窗体
*/
Chenxin.UI.RegContractForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    id: "jqmContractFrm",
    renderTo: "jqmContractFrm",
    actionUrl: "/service/logic/ShowListServiceCharge.ashx",
    title: "成交编号登记",
    op: "regcontractcode",
    defBBtn: true,
    //jqmWidth:460,
    createForm: function() {
        var strRet = "";
        strRet = strRet + '<table class="tbl_f" id="tbServiceCharge">';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th style="width:100px">服务费收据编号：</th>';
        strRet = strRet + '<td style="width:200px"><input type="text" name="ReceiptCode" readonly class="inputbox_n" /></td>';
        strRet = strRet + '<th style="width:100px">款项性质：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "ReceiptMoneyName" readonly /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>成交类型：</th>';
        strRet = strRet + '<td><input type="text" name="BusinessType" readonly class="inputbox_n" /></td>';
        strRet = strRet + '<th>客户姓名：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "CustomerName" readonly /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>金额：</th>';
        strRet = strRet + '<td><input type="text" name="GetedMoney" readonly class="inputbox_n" /></td>';
        strRet = strRet + '<th>领取时间：</th>';
        strRet = strRet + '<td><input type="text" name="GetedTime" readonly class="inputbox_n" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>收款部门：</th>';
        strRet = strRet + '<td><input type="text" name="ReceiptDepart" readonly class="inputbox_n" /></td>';
        strRet = strRet + '<th>收款人员：</th>';
        strRet = strRet + '<td><input type="text" name="ReceiptEmployee" readonly class="inputbox_n" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr style="height:10px;">';
        strRet = strRet + '<td colspan="4"></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr style="background-color:lightyellow;border:1px solid silver">';
        strRet = strRet + '<th>成交编号：</th>';
        strRet = strRet + '<td colspan="3">';
        strRet = strRet + '<input type="text" class="inputbox_n fl" name="ContractCode" id="RegConContractCode" />';
        strRet = strRet + '<div class="btn btn5 fl"><a title="获取成交信息" href="javascript:void(0)" id="aGetContractInfo"><span>获取成交信息</span></a></div>';
        strRet = strRet + '<div id="RegConContractCodeTip" style="float: left; margin-left: 5px; width: 180px; height: 26px; line-height: 26px; text-align: left;" ></div>';
        strRet = strRet + '</td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '</table>';
        strRet = strRet + '<table class="tbl_f" id="tbContractInfo" style="margin-top:0px">';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>房源地址：</th>';
        strRet = strRet + '<td colspan=3 style="width:400px"><input type="text" name="CHouseAddress" readonly class="inputbox_n" style="width:430px" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th style="width:100px">上家客户：</th>';
        strRet = strRet + '<td  style="width:200px"><input type="text" name="VenderName" readonly class="inputbox_n" /></td>';
        strRet = strRet + '<th style="width:100px">下家客户：</th>';
        strRet = strRet + '<td><input type="text" name="BuyerName" readonly class="inputbox_n" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>上家确认佣收：</th>';
        strRet = strRet + '<td><input type="text" name="VRealCommision" readonly class="inputbox_n" /></td>';
        strRet = strRet + '<th>下家确认佣收：</th>';
        strRet = strRet + '<td><input type="text" name="BRealCommision" readonly class="inputbox_n" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>上家咨询费：</th>';
        strRet = strRet + '<td><input type="text" name="VConsulting" readonly class="inputbox_n" /></td>';
        strRet = strRet + '<th>下家咨询费：</th>';
        strRet = strRet + '<td><input type="text" name="BConsulting" readonly class="inputbox_n" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>上家门店：</th>';
        strRet = strRet + '<td><input type="text" name="VenderDepartName" readonly class="inputbox_n" /></td>';
        strRet = strRet + '<th>下家门店：</th>';
        strRet = strRet + '<td><input type="text" name="BuyerDepartName" readonly class="inputbox_n" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>上家经纪人：</th>';
        strRet = strRet + '<td><input type="text" name="VenderUserName" readonly class="inputbox_n" /></td>';
        strRet = strRet + '<th>下家经纪人：</th>';
        strRet = strRet + '<td><input type="text" name="BuyerUserName" readonly class="inputbox_n" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '</table>';
        return strRet;
    },
    initFormValidator: function() {
        //成交编号
        $("#RegConContractCode").formValidator({
            validatorgroup: this.id,
            onshow: "请输入成交编号！",
            onfocus: "成交编号为必输项目",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "成交编号不能为空！"
            },
            onerror: "成交编号不能为空！"
        });
    },
    initEvent: function() {
        var objFrm = this;
        /*************事件：成交信息获取*************/
        $("#aGetContractInfo").click(function() {

            if ($("#RegConContractCode").val() == "") {
                alert("请输入成交编号！");
                return false;
            }
            Chenxin.ajax({
                type: "get",
                dataType: "text",
                paramType: 'json',
                async: false,
                url: objFrm.actionUrl,
                data: { op: 'getcontractinfo', ContractCode: $("#RegConContractCode").val() },
                onSuccess: function(data, msg) {
                    data.CHouseAddress = data.HouseAddress;
                    Chenxin.Fn.setFormValue("tbContractInfo", [], data);
                }
            });
        });
        /*************事件：成交编号失去焦点*************/
        $("#RegConContractCode").blur(function() {
            if ($("#RegConContractCode").val() != objFrm.PreCode) {
                objFrm.PreCode = $("#RegConContractCode").val()
                Chenxin.Fn.setFormValue("tbContractInfo", [], {});
            }
        });
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(function() {
    var objPg = new Chenxin.UI.PgServiceCharge();
});